﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.Resources.Core;
using Windows.UI.Xaml;

namespace Xiaowei.Models
{
    public class WeatherData
    {
        public static Dictionary<string, string> TextAndUrlMap;
        static WeatherData()
        {
            TextAndUrlMap = new Dictionary<string, string>();
            TextAndUrlMap.Add("晴", "/Assets/WeatherIcon/W0.png");
            TextAndUrlMap.Add("大部晴朗", "/Assets/WeatherIcon/W0.png");
            TextAndUrlMap.Add("多云", "/Assets/WeatherIcon/W1.png");
            TextAndUrlMap.Add("少云", "/Assets/WeatherIcon/W1.png");
            TextAndUrlMap.Add("阴", "/Assets/WeatherIcon/W2.png");
            TextAndUrlMap.Add("阵雨", "/Assets/WeatherIcon/W3.png");
            TextAndUrlMap.Add("局部阵雨", "/Assets/WeatherIcon/W3.png");
            TextAndUrlMap.Add("小阵雨", "/Assets/WeatherIcon/W3.png");
            TextAndUrlMap.Add("强阵雨", "/Assets/WeatherIcon/W3.png");
            TextAndUrlMap.Add("阵雪", "/Assets/WeatherIcon/W13.png");
            TextAndUrlMap.Add("小阵雪", "/Assets/WeatherIcon/W13.png");
            TextAndUrlMap.Add("雾", "/Assets/WeatherIcon/W18.png");
            TextAndUrlMap.Add("冻雾", "/Assets/WeatherIcon/W18.png");
            TextAndUrlMap.Add("沙尘暴", "/Assets/WeatherIcon/W20.png");
            TextAndUrlMap.Add("浮尘", "/Assets/WeatherIcon/W29.png");
            TextAndUrlMap.Add("尘卷风", "/Assets/WeatherIcon/W29.png");
            TextAndUrlMap.Add("扬沙", "/Assets/WeatherIcon/W29.png");
            TextAndUrlMap.Add("强沙尘暴", "/Assets/WeatherIcon/W20.png");
            TextAndUrlMap.Add("霾", "/Assets/WeatherIcon/W45.png");
            TextAndUrlMap.Add("雷阵雨", "/Assets/WeatherIcon/W4.png");
            TextAndUrlMap.Add("雷电", "/Assets/WeatherIcon/W4.png");
            TextAndUrlMap.Add("雷暴", "/Assets/WeatherIcon/W4.png");
            TextAndUrlMap.Add("雷阵雨伴", "/Assets/WeatherIcon/W5.png");
            TextAndUrlMap.Add("冰雹", "/Assets/WeatherIcon/W5.png");
            TextAndUrlMap.Add("冰针", "/Assets/WeatherIcon/W5.png");
            TextAndUrlMap.Add("冰粒", "/Assets/WeatherIcon/W5.png");
            TextAndUrlMap.Add("雨夹雪", "/Assets/WeatherIcon/W6.png");
            TextAndUrlMap.Add("小雨", "/Assets/WeatherIcon/W7.png");
            TextAndUrlMap.Add("中雨", "/Assets/WeatherIcon/W8.png");
            TextAndUrlMap.Add("大雨", "/Assets/WeatherIcon/W9.png");
            TextAndUrlMap.Add("暴雨", "/Assets/WeatherIcon/W10.png");
            TextAndUrlMap.Add("大暴雨", "/Assets/WeatherIcon/W10.png");
            TextAndUrlMap.Add("特大暴雨", "/Assets/WeatherIcon/W10.png");
            TextAndUrlMap.Add("小雪", "/Assets/WeatherIcon/W14.png");
            TextAndUrlMap.Add("中雪", "/Assets/WeatherIcon/W15.png");
            TextAndUrlMap.Add("大雪", "/Assets/WeatherIcon/W16.png");
            TextAndUrlMap.Add("暴雪", "/Assets/WeatherIcon/W17.png");
            TextAndUrlMap.Add("冻雨", "/Assets/WeatherIcon/W19.png");
            TextAndUrlMap.Add("雪", "/Assets/WeatherIcon/W15.png");
            TextAndUrlMap.Add("雨", "/Assets/WeatherIcon/W8.png");
            TextAndUrlMap.Add("小到中雨", "/Assets/WeatherIcon/W7.png");
            TextAndUrlMap.Add("中到大雨", "/Assets/WeatherIcon/W9.png");
            TextAndUrlMap.Add("大到暴雨", "/Assets/WeatherIcon/W10.png");
            TextAndUrlMap.Add("小到中雪", "/Assets/WeatherIcon/W15.png");
            TextAndUrlMap.Add("晴_晚上", "/Assets/WeatherIcon/W30.png");
            TextAndUrlMap.Add("大部晴朗_晚上", "/Assets/WeatherIcon/W30.png");
            TextAndUrlMap.Add("多云_晚上", "/Assets/WeatherIcon/W31.png");
            TextAndUrlMap.Add("少云_晚上", "/Assets/WeatherIcon/W31.png");
            TextAndUrlMap.Add("阴_晚上", "/Assets/WeatherIcon/W2.png");
            TextAndUrlMap.Add("阵雨_晚上", "/Assets/WeatherIcon/W33.png");
            TextAndUrlMap.Add("局部阵雨_晚上", "/Assets/WeatherIcon/W33.png");
            TextAndUrlMap.Add("小阵雨_晚上", "/Assets/WeatherIcon/W33.png");
            TextAndUrlMap.Add("强阵雨_晚上", "/Assets/WeatherIcon/W33.png");
            TextAndUrlMap.Add("阵雪_晚上", "/Assets/WeatherIcon/W34.png");
            TextAndUrlMap.Add("小阵雪_晚上", "/Assets/WeatherIcon/W34.png");
            TextAndUrlMap.Add("雾_晚上", "/Assets/WeatherIcon/W32.png");
            TextAndUrlMap.Add("冻雾_晚上", "/Assets/WeatherIcon/W32.png");
            TextAndUrlMap.Add("沙尘暴_晚上", "/Assets/WeatherIcon/W36.png");
            TextAndUrlMap.Add("浮尘_晚上", "/Assets/WeatherIcon/w35.png");
            TextAndUrlMap.Add("尘卷风_晚上", "/Assets/WeatherIcon/W35.png");
            TextAndUrlMap.Add("扬沙_晚上", "/Assets/WeatherIcon/W35.png");
            TextAndUrlMap.Add("强沙尘暴_晚上", "/Assets/WeatherIcon/W36.png");
            TextAndUrlMap.Add("霾_晚上", "/Assets/WeatherIcon/W46.png");
            TextAndUrlMap.Add("雷阵雨_晚上", "/Assets/WeatherIcon/W4.png");
            TextAndUrlMap.Add("雷电_晚上", "/Assets/WeatherIcon/W4.png");
            TextAndUrlMap.Add("雷暴_晚上", "/Assets/WeatherIcon/W4.png");
            TextAndUrlMap.Add("雷阵雨伴_晚上", "/Assets/WeatherIcon/W5.png");
            TextAndUrlMap.Add("冰雹_晚上", "/Assets/WeatherIcon/W5.png");
            TextAndUrlMap.Add("冰针_晚上", "/Assets/WeatherIcon/W5.png");
            TextAndUrlMap.Add("冰粒_晚上", "/Assets/WeatherIcon/W5.png");
            TextAndUrlMap.Add("雨夹雪_晚上", "/Assets/WeatherIcon/W6.png");
            TextAndUrlMap.Add("小雨_晚上", "/Assets/WeatherIcon/W7.png");
            TextAndUrlMap.Add("中雨_晚上", "/Assets/WeatherIcon/W8.png");
            TextAndUrlMap.Add("大雨_晚上", "/Assets/WeatherIcon/W9.png");
            TextAndUrlMap.Add("暴雨_晚上", "/Assets/WeatherIcon/W10.png");
            TextAndUrlMap.Add("大暴雨_晚上", "/Assets/WeatherIcon/W10.png");
            TextAndUrlMap.Add("特大暴雨_晚上", "/Assets/WeatherIcon/W10.png");
            TextAndUrlMap.Add("小雪_晚上", "/Assets/WeatherIcon/W14.png");
            TextAndUrlMap.Add("中雪_晚上", "/Assets/WeatherIcon/W15.png");
            TextAndUrlMap.Add("大雪_晚上", "/Assets/WeatherIcon/W16.png");
            TextAndUrlMap.Add("暴雪_晚上", "/Assets/WeatherIcon/W17.png");
            TextAndUrlMap.Add("冻雨_晚上", "/Assets/WeatherIcon/W19.png");
            TextAndUrlMap.Add("雪_晚上", "/Assets/WeatherIcon/W15.png");
            TextAndUrlMap.Add("雨_晚上", "/Assets/WeatherIcon/W8.png");
            TextAndUrlMap.Add("小到中雨_晚上", "/Assets/WeatherIcon/W7.png");
            TextAndUrlMap.Add("中到大雨_晚上", "/Assets/WeatherIcon/W9.png");
            TextAndUrlMap.Add("大到暴雨_晚上", "/Assets/WeatherIcon/W10.png");
            TextAndUrlMap.Add("小到中雪_晚上", "/Assets/WeatherIcon/W15.png");
        }
        public string Condition { get; set; }
        public string Day
        {
            get
            {
                switch (DateTimeOffset.Parse(Date).DayOfWeek)
                {
                    case DayOfWeek.Sunday:
                        return "周日";
                    case DayOfWeek.Monday:
                        return "周一";
                    case DayOfWeek.Tuesday:
                        return "周二";
                    case DayOfWeek.Wednesday:
                        return "周三";
                    case DayOfWeek.Thursday:
                        return "周四";
                    case DayOfWeek.Friday:
                        return "周五";
                    case DayOfWeek.Saturday:
                        return "周六";
                    default:
                        break;
                }
                return "";
            }
        }
        public string Date { get; set; }
        public string DateShort
        {
            get
            {
                return Date.Substring(5);
            }
        }
        public string MaxTemperature { get; set; }
        public string MinTemperature { get; set; }
        public string Temperature { get; set; }
        public string PM25 { get; set; }
        public string Quality { get; set; }
        public string WindDirection { get; set; }
        public string WindLevel { get; set; }
        public string IconUrl
        {
            get
            {

                if (!TextAndUrlMap.ContainsKey(Condition))
                {
                    return "ms-appx:///Assets/WeatherIcon/W44.png";
                }
                return TextAndUrlMap[Condition];
            }
        }
    }
    public class WeatherModel
    {

        public string Location { get; set; }
        public int currentInfo { get; set; } = -1;
        public string Condition
        {
            get
            {
                if (currentInfo != -1 && currentInfo < InfoList.Count)
                    return InfoList[currentInfo].Condition;
                return "";
            }
        }
        public string Date
        {
            get
            {
                if (currentInfo != -1 && currentInfo < InfoList.Count)
                    return InfoList[currentInfo].Date;
                return "";
            }
        }
        public string Day
        {
            get
            {
                if (currentInfo != -1 && currentInfo < InfoList.Count)
                {
                    switch (DateTimeOffset.Parse(InfoList[currentInfo].Date).DayOfWeek)
                    {
                        case DayOfWeek.Sunday:
                            return "周日";
                        case DayOfWeek.Monday:
                            return "周一";
                        case DayOfWeek.Tuesday:
                            return "周二";
                        case DayOfWeek.Wednesday:
                            return "周三";
                        case DayOfWeek.Thursday:
                            return "周四";
                        case DayOfWeek.Friday:
                            return "周五";
                        case DayOfWeek.Saturday:
                            return "周六";
                        default:
                            break;
                    }
                }
                return "";
            }
        }
        public string MaxTemperature
        {
            get
            {
                if (currentInfo != -1 && currentInfo < InfoList.Count)
                    return InfoList[currentInfo].MaxTemperature;
                return "";
            }
        }
        public string MinTemperature
        {
            get
            {
                if (currentInfo != -1 && currentInfo < InfoList.Count)
                    return InfoList[currentInfo].MinTemperature;
                return "";
            }
        }
        public string Temperature
        {
            get
            {
                if (currentInfo != -1 && currentInfo < InfoList.Count)
                    return InfoList[currentInfo].Temperature;
                return "";
            }
        }
        public string PM25
        {
            get
            {
                if (currentInfo != -1 && currentInfo < InfoList.Count)
                    return InfoList[currentInfo].PM25;
                return "";
            }
        }
        public string Quality
        {
            get
            {
                if (currentInfo != -1 && currentInfo < InfoList.Count)
                    return InfoList[currentInfo].Quality;
                return "";
            }
        }
        public string WindDirection
        {
            get
            {
                if (currentInfo != -1 && currentInfo < InfoList.Count)
                    return InfoList[currentInfo].WindDirection;
                return "";
            }
        }
        public string WindLevel
        {
            get
            {
                if (currentInfo != -1 && currentInfo < InfoList.Count)
                    return InfoList[currentInfo].WindLevel;
                return "";
            }
        }
        public string TempRange
        {
            get
            {
                if (currentInfo != -1 && currentInfo < InfoList.Count)
                    return MinTemperature.ToString() + "~" + MaxTemperature.ToString();
                return "Error";
            }
        }
        public string IconUrl
        {
            get
            {
                if (currentInfo != -1 && currentInfo < InfoList.Count)
                    return InfoList[currentInfo].IconUrl;
                return "/Assets/WeatherIcon/44.png";
            }

        }
        public Visibility TempVisibility
        {
            get
            {
                return string.IsNullOrEmpty(Temperature) ? Visibility.Collapsed : Visibility.Visible;
            }
        }
        public Visibility PM25Visibility
        {
            get
            {
                return string.IsNullOrEmpty(PM25) ? Visibility.Collapsed : Visibility.Visible;
            }
        }
        //private IList<WeatherDataMeta> alertList = new List<WeatherDataMeta>();
        private IList<WeatherData> infoList = new List<WeatherData>();

        //public IList<WeatherDataMeta> WeatherDataMetas { get => alertList; set => alertList = value; }
        public IList<WeatherData> InfoList { get => infoList; set => infoList = value; }
        public IList<WeatherData> FutureFiveDay
        {
            get
            {
                if(infoList.Count<7)return new List<WeatherData>();
                return new List<WeatherData>()
                {
                    infoList[2],
                    infoList[3],
                    infoList[4],
                    infoList[5],
                    infoList[6]
                };
            }
        }
    }
}
